<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/static/bootstrap-5.1.3-dist/css/bootstrap.css">
    <script type="text/javascript" src="/static/bootstrap-5.1.3-dist/js/bootstrap.js"></script>
    <title>帖子列表</title>
</head>

<style>
    .card {
        width: 1600px;
        height: 650px;
        background-color: #fffdfd;
        margin-left: 50px;
        margin-top: 40px;
        border-radius: 30px;
        border: none;
        box-shadow: 5px 5px 10px #adabab;
    }
    .operate {
        padding: 20px 40px;
    }

    .operate button {
        border: solid;
        width: 150px;
    }

    table {
        text-align: center;
        vertical-align: middle !important;
        word-wrap:break-all;
        word-break:break-all;
        table-layout:fixed;

        width: 90% !important;
        margin-left: 80px;

    }

    .page {
        height: 50px;
        /*width: 1270px;*/
        /*margin-left: 1400px;*/
        position: fixed;
        bottom: 180px;
        right: 150px;
    }

</style>

<body>
<jsp:include page="static/Page/common/Navbar.jsp"/>

<div class="card">
    <div class="search">
        <form class="operate" method="get" action="post_list" >
            <input name="method" value="query" class="input-text form-control" type="hidden">
            <div class="row" >
                <div class="col-md-4">
                    <div class="row">
                        <div class="col-sm-3" >
                            <label style="margin-top: 10px">查询帖子</label>
                        </div>
                        <div class="col-sm-6"  >
                            <input class="form-control" placeholder="请输入内容" name="postKeys" type="text" value="${postKey}" autocomplete="on">
                        </div>
                        <div class="col-sm-3">
                            <input value="查 询" type="submit" class="btn btn-outline-secondary" id="searchbutton">
                        </div>
                    </div>
                </div>
                <input type="hidden" name="page" value="1"/>
                <div class="col-md-5" style="margin-left: 380px">
                    <div class="row">
                        <div class="col-sm-3">
                            <a href="write.jsp" class="btn btn-outline-primary" role="button">添加帖子</a>
                        </div>
                        <div class="col-sm-3">
                            <a href="collec_post" class="btn btn-outline-primary" role="button">我的收藏</a>
                        </div>
                        <div class="col-sm-3">
                            <a href="adoption_request_display" class="btn btn-outline-primary " role="button">领养请求</a>
                        </div>
                    </div>

                </div>

            </div>
<%--            <input name="method" value="query" class="input-text form-control" type="hidden">--%>
<%--            <span>查询帖子：</span>--%>
<%--            <input name="postKeys" type="text" value="${postKey}" autocomplete="on">--%>
<%--            <input type="hidden" name="page" value="1"/>--%>
<%--            <input value="查 询" type="submit" class="btn btn-info" id="searchbutton">--%>
<%--            <a href="write.jsp" class="btn btn-primary " role="button">添加帖子</a>--%>
<%--            <a href="collec_post" class="btn btn-primary " role="button">我收藏的帖子</a>--%>
<%--            <a href="adoption_request_display" class="btn btn-primary " role="button">查看领养请求</a>--%>
        </form>
    </div>
    <table id="test" class="table table-bordered table-striped">
        <colgroup>
            <col width="150">
            <col width="200">
            <col width="200">
            <col width="250">
            <col width="200">
        </colgroup>
        <thead>
        <tr>
            <th>发帖人头像</th>
            <th>发帖人</th>
            <th>主题</th>
            <th>时间</th>
            <th>领养</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${posts}" var="post" varStatus="s">
            <c:forEach items="${userList}" var="user" varStatus="s1">
                <c:if test="${user.id == post.userid}">
                    <tr>
                        <td>
                            <img src="${pageContext.request.contextPath}/display?photo=${user.photo}" style="width: 100px;height: 100px">
                        </td>
                        <td><a href="ones_post_list?userid=${user.id}" class="btn-outline-secondary">${user.username}</a></td>
                        <td><a href="commentList?pid=${post.id}" } class="btn-outline-secondary">${post.title}</a></td>
                        <td>${post.date}</td>
                        <td><a href="establish_adoption_request?pid=${post.id}&hostid=${post.userid}" class="btn btn-outline-info">领养</a></td>
                        <td><a href="collect?pid=${post.id}" type="button" class="btn btn-outline-success">收藏</a></td>
                    </tr>
                </c:if>
            </c:forEach>
        </c:forEach>
        </tbody>
    </table>

    <div class="page">
        <nav aria-label="Page navigation example">
            <ul class="pagination justify-content-between">
                <c:if test="${pageInfo.isLast && falg == null}">
                    <li><a href="post_list?page=${pageInfo.pageIndex-1}" class="page-link"><span
                            aria-hidden="true">&larr;</span> 上一页</a></li>
                </c:if>
                <c:if test="${pageInfo.isNext && falg == null}">
                    <li><a href="post_list?page=${pageInfo.pageIndex+1}" class="page-link">下一页 <span
                            aria-hidden="true">&rarr;</span></a></li>
                </c:if>

            </ul>
            <span>第 ${pageInfo.pageIndex} 页/共 ${pageInfo.sumCount} 页</span>
        </nav>
    </div>

</div>


<jsp:include page="static/Page/common/Foot.jsp"/>
</body>
</html>